﻿Option Explicit On
Option Strict On

Imports System.Web.SessionState
Imports JPC.Medialibrary.DAL
Imports JPC.Medialibrary.UI

Namespace JPC.Medialibrary.BLL

    Public Enum ePlayerStatus
        Playing
        Paused
        Stopped
    End Enum

    Public Enum eListViewMode
        List
        Thumbnail
    End Enum

    Public NotInheritable Class MySession

        Private Const BreadcrumbListKey As String = "BreadCrumbList"
        Private Const LastBreadcrumbKey As String = "LastBreadcrumb"

        'Estado del Player -> Playing - Paused - Stopped
        Private Const playerStatusKey As String = "playerStatus"

        'Lista de Canciones en la solapa "Selected"
        'Pueden o no estar sonando. Lo sabemos chequeando isPlayingFromPlaylist
        Private Const currentPlaylistSongsKey As String = "currentPlaylistSongs"

        'selectedSong es la canción que está sonando en este momento
        'Puede o no estar en la playlist. Lo sabemos chequeando isPlayingFromPlaylist
        Private Const selectedSongKey As String = "selectedSong"

        'isPlayingFromPlaylist indica si "selectedSong" es de la Playlist
        Private Const isPlayingFromPlaylistKey As String = "isPlayingFromPlaylist"

        'currentMenu tiene el Menu seleccionado
        Private Const currentMenuKey As String = "currentMenu"

        'currentPlaylist es la Playlist en uso
        Private Const currentPlayListKey As String = "currentPlaylist"

        'listViewMode puede ser "List" o "Thumbnails"
        Private Const listViewModeKey As String = "listViewMode"

        Private Sub New()
        End Sub

        Private Shared ReadOnly Property Session() As HttpSessionState
            Get
                Return HttpContext.Current.Session
            End Get
        End Property

        Public Shared ReadOnly Property Exists() As Boolean
            Get
                Return Not Session Is Nothing
            End Get
        End Property

        Public Shared Property BreadCrumbList() As BreadcrumbList
            Get
                Try
                    Return DirectCast(Session(BreadcrumbListKey), BreadcrumbList)
                Catch ex As Exception
                    Return New BreadcrumbList
                End Try
            End Get
            Set(ByVal value As BreadcrumbList)
                Session(BreadcrumbListKey) = value
            End Set
        End Property

        Public Shared Property LastBreadcrumb() As ListItem
            Get
                Try
                    Return DirectCast(Session(LastBreadcrumbKey), ListItem)
                Catch ex As Exception
                    Return New ListItem
                End Try
            End Get
            Set(ByVal value As ListItem)
                Session(LastBreadcrumbKey) = value
            End Set
        End Property

        Public Shared Property currentPlaylistSongs() As currentPlaylistSongs
            Get
                Try
                    If DirectCast(Session(currentPlaylistSongsKey), currentPlaylistSongs) Is Nothing Then
                        Return New currentPlaylistSongs
                    Else
                        Return DirectCast(Session(currentPlaylistSongsKey), currentPlaylistSongs)
                    End If
                Catch ex As Exception
                    Return New currentPlaylistSongs
                End Try
            End Get
            Set(ByVal value As currentPlaylistSongs)
                Session(currentPlaylistSongsKey) = value
            End Set
        End Property

        Public Shared Property SelectedSong() As Song
            Get
                Try
                    Return DirectCast(Session(selectedSongKey), Song)
                Catch ex As Exception
                    Return New Song
                End Try
            End Get
            Set(ByVal value As Song)
                Session(selectedSongKey) = value
            End Set
        End Property

        Public Shared Property isPlayingFromPlaylist() As Boolean
            Get
                Try
                    Return DirectCast(Session(isPlayingFromPlaylistKey), Boolean)
                Catch ex As Exception
                    Return False
                End Try
            End Get
            Set(ByVal value As Boolean)
                Session(isPlayingFromPlaylistKey) = value
            End Set
        End Property

        Public Shared Property playerStatus() As ePlayerStatus
            Get
                Try
                    Return DirectCast(Session(playerStatusKey), ePlayerStatus)
                Catch ex As Exception
                    Return ePlayerStatus.Stopped
                End Try
            End Get
            Set(ByVal value As ePlayerStatus)
                Session(playerStatusKey) = value
            End Set
        End Property

        Public Shared Property CurrentMenu() As String
            Get
                Try
                    Return DirectCast(Session(currentMenuKey), String)
                Catch ex As Exception
                    Return ""
                End Try
            End Get
            Set(ByVal value As String)
                Session(currentMenuKey) = value
            End Set
        End Property

        Public Shared Property CurrentPlaylist() As Playlist
            Get
                Try
                    Return DirectCast(Session(currentPlayListKey), Playlist)
                Catch ex As Exception
                    Return New Playlist
                End Try
            End Get
            Set(ByVal value As Playlist)
                Session(currentPlayListKey) = value
            End Set
        End Property

        Public Shared Property ListViewMode() As eListViewMode
            Get
                Try
                    Return DirectCast(Session(listViewModeKey), eListViewMode)
                Catch ex As Exception
                    Return 0
                End Try
            End Get
            Set(ByVal value As eListViewMode)
                Session(listViewModeKey) = value
            End Set
        End Property

    End Class

End Namespace